<?php
/**
 * https://gitee.com/Mao02
 * http://www.dazhetu.cn/
 * jay_fun 410136330@qq.com
 * Date: 2018/9/29
 * Time: 23:44
 */

namespace app\blog\widget;

use app\common\model\content\Category;
use app\common\model\content\Reply;
use app\common\model\content\Tags;
use think\Controller;

/**
 * 博客小部件
 * Class Blog
 * @package app\blog\widget
 */
class Blog extends Controller
{
    /**
     * 导航中的分类标签
     * @return mixed
     * @throws \think\exception\DbException
     */
    public function nav()
    {
        $category = Category::all(['state'=>1,'is_deleted'=>0]);
        $this->assign('category',$category);
        return $this->fetch('widget/nav');
    }

    /**
     * 标签云小部件
     * @return mixed
     * @throws \think\exception\DbException
     */
    public function tags_cloud()
    {
        return $this->fetch('widget/tags_cloud',['tags'=>Tags::all()]);
    }

    /**
     * 最新评论小部件
     * @return mixed
     */
    public function latest_reply()
    {
        $replies = Reply::where('state',1)->order('id desc')->limit(5)->select();
        return $this->fetch('widget/latest_reply', ['replies'=>$replies]);
    }
}